package omm.domain.comparativegraph;

import java.util.List;

import org.joda.time.DateTime;

import omm.dao.OrderDAO;
import omm.dao.QuotationDAO;
import omm.dao.imp.QuotationAndOrderAndEntityStrategy;
import omm.dao.imp.QuotationAndOrderAndRiskStrategy;
import omm.domain.CommissionStrategy;
import omm.domain.Quotation;
import omm.domain.enums.Commission;
import omm.domain.enums.GraphicType;
import omm.domain.enums.GroupBy;

public class ComparativeGraphicFactory {
	
	public ComparativeGraphic createComparativeGraphic( QuotationDAO quotationDAO, OrderDAO orderDAO,
			GraphicType graphicType, Commission commissionState, GroupBy groupbyState) {

		GraphicStrategy graphicStrategy = null;
		GroupStrategy groupStrategy = null;
		CommissionStrategy commissionStrategy = new CommissionStrategy(commissionState);
		
		DateTime ending = DateTime.now();
		DateTime beginning = ending.minusDays(365);
		
		List<Quotation> quotations;
		if (groupbyState.equals(GroupBy.PRODUCT)){
			quotations = quotationDAO.getAllWithFilter(new QuotationAndOrderAndRiskStrategy(orderDAO),beginning,ending);
			groupStrategy = new ProductStrategy();
		}else{
			quotations = quotationDAO.getAllWithFilter(new QuotationAndOrderAndEntityStrategy(orderDAO),beginning,ending);
			groupStrategy = new EntityStrategy();
		}
				
		switch (graphicType) {
		case BAR:
			graphicStrategy = new BarGraphicStrategy();break;
		case PIE:
			graphicStrategy = new PieGraphicStrategy();break;
		}

		return new ComparativeGraphic(quotations, graphicStrategy, commissionStrategy, groupStrategy);
	}
	
	
}



